from aip import AipFace
import base64

def face_rg(file_Path):
    """ 你的 APPID AK SK """
    APP_ID = '28400659'
    API_KEY = 'R0QlKMEQux4XEHYRHAPiELPN'
    SECRET_KEY = 'CtMxGBVpC6NilebQwCzNC6B9FABSbm5g'

    client = AipFace(APP_ID, API_KEY, SECRET_KEY)

    with open(file_Path, 'rb') as file:
        data = base64.b64encode(file.read())  # 图片类型BASE64：图片的base64值：base64编码后的图片数据

    image = data.decode()  # 解码

    image_type = 'BASE64'
    options = {}

    options["face_field"] = "beauty"
    options["max_face_num"] = 2
    options["face_type"] = "LIVE"
    options["liveness_control"] = "LOW"

    """ 调用人脸检测 """
    result = client.detect(image, image_type, options)
    print(result['result']['face_list'][0]['beauty'])
    return result['result']['face_list'][0]['beauty']


if __name__ == '__main__':
    face_rg(fr"D:\py\16 爬虫2\212 虎牙颜值排行\img\eStar-眼里有你.jpg")
    face_rg(fr"C:\Users\ping\Pictures\Camera Roll\1.jpg")
    face_rg(fr"C:\Users\ping\Pictures\Camera Roll\2.jpg")
    face_rg(fr"C:\Users\ping\Pictures\Camera Roll\宁.jpg")
    face_rg(fr"C:\Users\ping\Pictures\Camera Roll\吴.jpg")
    face_rg(fr"C:\Users\ping\Pictures\Camera Roll\陈.jpg")
    face_rg(fr"C:\Users\ping\Pictures\mn\02.jpg")

